﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class numberCCL : MonoBehaviour {

	// Use this for initialization
    public Sprite[] nums;
    private manCCL man;
    public GameObject baiweiSp;
    public GameObject shiweiSp;
    public GameObject geweiSp;


    public bool isShowHighNum;
    

	void Start () 
    {
        man = GameObject.FindGameObjectWithTag("Player").GetComponent<manCCL>();
        
        if (isShowHighNum)
        {
            showHighCount();
           // print("---");
        }
        else
        {
            showCount(man.numberCount);
           // print("+++");
        }
	}

    private void showHighCount()
    {
        //判断当前是否大于最高
        if (man.numberCount>playerPrefer.count)
        {
            PlayerPrefs.SetInt("count", man.numberCount);
            playerPrefer.count = man.numberCount;
            showCount(man.numberCount);
          //  print(PlayerPrefs.GetInt("count"));
        }
        else
        {

            showCount(playerPrefer.count); 
        }
    }
    
	
	// Update is called once per frame
    public void  showCount(int count) 
    {
       // print("修改现实");
        string i = count.ToString();
        int k = i.Length;
        if (k==1)
        {
            i = "00" + i;
        }
        else if (k==2)
        {
            i = "0" + i;
        }
        string baiwei = i.Substring(0,1);
        string shiwei = i.Substring(1,1);
        string gewei = i.Substring(2,1);
        baiweiSp.GetComponent<Image>().sprite = nums[int.Parse(baiwei)];
        shiweiSp.GetComponent<Image>().sprite = nums[int.Parse(shiwei)];
        geweiSp.GetComponent<Image>().sprite = nums[int.Parse(gewei)];
        //baiwei.ge


    }
}
